package com.atguigu.yygh.user.controller.admin;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.vo.acl.UserQueryVo;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * ClassName: AdminUserinfoController
 * Package: com.atguigu.yygh.user.controller.admin
 * Description:
 *
 * @Author: cqk
 * @Create: 2023/9/27 - 9:29
 * @Version: v1.0
 */
@RestController
@RequestMapping("/administrator/userinfo")
public class AdminUserinfoController {
    @Autowired
    private UserInfoService userInfoService;

    //查看用户下面负责的病人信息

    @GetMapping("/detail/{id}")
    public R detail(@PathVariable Long id){
        Map<String,Object> map = userInfoService.detail(id);
        return R.ok().data(map);
    }


    @GetMapping("/{pageNum}/{limit}")
    public R getUserInfoPage(@PathVariable Integer pageNum,
                             @PathVariable Integer limit,
                             UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> page = userInfoService.getUserInfoPage(pageNum,limit,userInfoQueryVo);
        return R.ok().data("total",page.getTotal()).data("list",page.getRecords());
    }

    //修改用户操作
    @PutMapping("/{id}/{status}")
    public R updateStatus(@PathVariable Long id,
                          @PathVariable Integer status){
        userInfoService.updateStatus(id,status);
        return R.ok();
    }

    
    //修改用户认证状态操作
    @PutMapping("/auth/{id}/{authStatus}")
    public R updateAuth(@PathVariable Long id,
                        @PathVariable Integer authStatus){
        UserInfo userInfo = new UserInfo();
        userInfo.setId(id);
        userInfo.setAuthStatus(authStatus);
        userInfoService.updateById(userInfo);
        return R.ok();
    }

}
